'use strict';

/**
 * @ngdoc function
 * @name appApp.controller:ResourceArticleListCtrl
 * @description
 * # ResourceArticleListCtrl
 * Controller of the appApp
 */
angular.module('appApp')
  .controller('ResourceArticleListCtrl', function ($scope, onlineFac, $routeParams) {
  	$scope.content_type = 0;
	  $scope.currentPage = 1;
	  //设置每页数量
	  $scope.perPage = 5;

    $scope.getArticles = function(){
    	$scope.article_list = null;
	    onlineFac.article.articles({
	      category_id: $routeParams.listId,
	      content_type: $scope.content_type,
	      page: $scope.currentPage
	    },function(data){
	      $scope.article_list = data.info;
	      $scope.totalItems = data.total;
	    },function(data){
	      alert(data.data.info);
	    });
	  }

	  $scope.setCurrentType = function(type){
    	$scope.content_type = type;
    	$scope.currentPage = 1;
    	$scope.keywords = null;
    	$scope.getArticles();
	  }

	  $scope.search = function(page){
    	$scope.article_list = null;
    	$scope.content_type = 0;
    	$scope.currentPage = page;
	    onlineFac.article.search({
	      category_id: $routeParams.listId,
	      keywords: $scope.keywords,
	      page: $scope.currentPage
	    },function(data){
	      $scope.article_list = data.info;
	      $scope.totalItems = data.total;
	    },function(data){
	      alert(data.data.info);
	    });
	  }

  });
